{% extends 'base.html' %}
{% block title %}添加定时任务{% endblock %}
{% block content %}
<div class="span9" id="content">
    <div class="block">
        <div class="navbar navbar-inner block-header">
            <div class="muted pull-left">添加定时任务</div>
        </div>
        <h5 style="color: red">{{ msg }}</h5>
        <div class="block-content collapse in">
            <p class="span12">
            <div class="table-toolbar">
                <div class="btn-group">
                </div>
            </div>
            <form class="form-signin" method="post" action="{% url 'addting' %}"  enctype="multipart/form-data">
                {% csrf_token %}
                <p>
                    <span> <strong>项目：</strong></span>
                    <select name="project" id="project" onclick="testall()">
                        {% for project in projects %}
                        <option>{{ project.name }}</option>
                        {% endfor %}
                    </select>
                </p>
                <p>
                    <span><strong>测试环境：</strong></span>
                    <select id="testevent" name="testevent" onclick="testcase()"></select>
                </p>
                <p>
                    <span><strong>任务类型：</strong></span>
                    <select id="tasktype" name="tasktype">
                        <option>一次性任务</option>
                        <option>定时任务</option>
                    </select>

                </p>
                <p>
                    <span><strong>case类型：</strong></span>
                    <select id="casetype" name="casetype">
                        <option>UIcase</option>
                        <option>UI遍历</option>
                        <option>UImonkey</option>
                    </select>
                </p>
                <p>
                    <span><strong>任务的名字：</strong></span>
                    <input name="name" placeholder="定时任务的名字">
                </p>

                <p>
                    <span><strong>用例编号：</strong></span>
                    <span id="testcase"></span>
                </p>
                <p>
                    <strong>执行时间表达式</strong>
                     <select id="week_day" name="week_day">
                        <option>mon</option>
                        <option>tue</option>
                        <option>wed</option>
                           <option>thu</option>
                           <option>fri</option>
                           <option>sat</option>
                           <option>sun</option>
                          <option>mon-tue</option>
                           <option>mon-wed</option>
                           <option>tue-wed</option>
                          <option>mon-thu</option>
                           <option>tue-thu</option>
                         <option>wed-thu</option>
                             <option>mon-fri</option>
                           <option>tue-fri</option>
                         <option>wed-fri</option>
                           <option>thu-fri</option>
                         <option>mon-sat</option>
                           <option>tue-sat</option>
                         <option>wed-sat</option>
                           <option>thu-sat</option>
                           <option>fri-sat</option>
                          <option>mon-sun</option>
                           <option>tue-sun</option>
                         <option>wed-sun</option>
                           <option>thu-sun</option>
                           <option>fri-sun</option>
                           <option>sat-sun</option>
                    </select>
                    <select id="hour" name="hour">
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                    </select>
                     <select id="minute" name="minute">
                       <option>1</option>
                        <option>2</option>
                        <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                         <option>25</option>
                         <option>26</option>
                         <option>27</option>
                         <option>28</option>
                         <option>29</option>
                          <option>30</option>
                         <option>31</option>
                         <option>32</option>
                         <option>33</option>
                         <option>34</option>
                         <option>35</option>
                         <option>36</option>
                         <option>37</option>
                         <option>38</option>
                         <option>39</option>
                         <option>40</option>
                         <option>41</option>
                         <option>42</option>
                         <option>43</option>
                         <option>44</option>
                         <option>45</option>
                         <option>46</option>
                         <option>47</option>
                         <option>48</option>
                         <option>49</option>
                         <option>50</option>
                          <option>51</option>
                         <option>52</option>
                         <option>53</option>
                         <option>54</option>
                         <option>55</option>
                         <option>56</option>
                         <option>57</option>
                         <option>58</option>
                         <option>59</option>
                    </select>
                </p>
                <p>
                    <input type="file" name="apkfile" />
                </p>
                <input type="submit" class="button btn-default" value="添加">
            </form>
        </div>
    </div>
</div>
{% endblock %}
{% block js %}
window.onload=testevet();
function testall(){
testevet();
testcase();
}
function testevet() {
var obj = document.getElementById('project');
var index=obj.selectedIndex;
var meth = obj.options[index].value;
var testvents= $("#testevent");
$.ajax({
url: '{%  url 'gettestcase' %}',
type: 'POST',
data:  meth,
contentType: 'application/json; charset=UTF-8',
processData: false,
success: function (result) {
if (result['code'] == 200) {
testvents.empty();
for (var i = 0; i < result['data'].length; i++) {
var obj = result['data'][i];
testvents.append("<option>" + obj.testevent + "</option>");}
;
}
else {
alert(result['msg']);
}
}
});
};
function testcase() {
var obj = document.getElementById('project');
var index=obj.selectedIndex;
var meth = obj.options[index].value;
var ob = document.getElementById('testevent');
var inde=ob.selectedIndex;
var met = ob.options[inde].value;
var testcase= $("#testcase");
var data={};
data['project']=meth;
data['testvent']=met;
$.ajax({
url: '{%  url 'get_test_case' %}',
type: 'POST',
data:   JSON.stringify(data),
contentType: 'application/json; charset=UTF-8',
processData: false,
success: function (result) {
if (result['code'] == 200) {
testcase.empty();
for (var i = 0; i < result['data'].length; i++) {
var obj = result['data'][i];
testcase.append("<input type='checkbox' value=" + obj.case + " name='case'>"+obj.case);

}
;
}
else {
alert(result['msg']);
}
}
});
};

{% endblock %}